


Object.myAssgin=function (target,...src) {
    for(let i=0;i<src.length;i++){
        if (src[i]!==null||src[i]!==undefined){
            for(let key in src[i]){
                if(src[i].hasOwnProperty(key)){
                    target[key]=src[i][key]
                }
            }
        }
    }
        return target
}

function humpToUnderLine(str) {
    var temp=str.replace(/[A-Z]/g,function(match){
        return '_'+match.toLowerCase()
    })
    if(temp.slice(0,1)==='_'){
        temp=temp.slice(1)
    }
    return temp
}
var str='QaFFbdf';

console.log(humpToUnderLine(str));

const data = [
    {
        id: 3,
        name: 'bbbb',
        parendId: null
    },
    {
        id: 2,
        name: 'aaaaa',
        parendId: null
    },
    {
        id: 4,
        name: 'ggggg',
        parendId: 2
    },
    {
        id: 5,
        name: 'hhhhh',
        parendId: 1
    },
    {
        id: 6,
        name: 'jjjj',
        parendId: 3
    },
    {
        id: 1,
        name: 'ccc',
        parendId: null
    }
];

function buildTree(list){
    let temp = {};
    let tree = [];
    for(let i in list){
        temp[list[i].id] = list[i];
    }

    for(let i in temp){

        if(temp[i].parendId) {
            if(!temp[temp[i].parendId].children) {
                temp[temp[i].parendId].children = [];
            }
            temp[temp[i].parendId].children.push(temp[i]);
        } else {
            tree.push(temp[i]);
        }
    }

    console.log(JSON.stringify(tree));
    return tree;
}
buildTree(data);









